package com.zhhtech.zhh.ui.activity.main

import android.view.View
import com.zhhtech.zhh.api.api
import com.zhhtech.zhh.api.core.launchUI
import com.zhhtech.zhh.api.core.toData
import com.zhhtech.zhh.common.UserCache
import com.zhhtech.zhh.databinding.ActivityWithdrawBinding
import com.zhhtech.zhh.ui.api.ApiObserver
import com.zhhtech.zhh.ui.base.BaseActivity
import com.zhhtech.zhh.ui.ext.startActivityExt
import com.zhhtech.zhh.ui.ext.toastMessageLong
import com.zhhtech.zhh.ui.ext.value
import com.zhhtech.zhh.ui.utils.variableView

class WithdrawActivity : BaseActivity<ActivityWithdrawBinding>() {

    override fun initView() {
        bindViewClick(vb.buttonSubmit, vb.text1)
        variableView {
            addTextView(vb.etAmount)
            addOnValidationResultListener(vb.buttonSubmit)
        }
        vb.tvInviteIncome.text = UserCache.getUserInfoBean().balance
    }

    override fun onClick(v: View?) {
        when (v) {
            vb.text1 -> startActivityExt<IncomeListActivity>()
            vb.buttonSubmit -> {
                launchUI({
                    api.withdraw(vb.etAmount.value).toData()
                    val user = api.userInfo().toData() ?: return@launchUI
                    UserCache.saveUserInfoBean(user)
                    "提现申请成功".toastMessageLong()
                }, ApiObserver(mThis))
            }
        }
    }
}